home *** CD-ROM | disk | FTP | other *** search
/ Windows Expert / Windows Expert.iso / windownt / wvnsrc75.zip / WVCNCM.C < prev    next >
C/C++ Source or Header  |  1992-11-09  |  14KB  |  584 lines

  1. /*-- This is the first line of WVCNCM.C -------------------------------*/
  2.  
  3. #include <stdlib.h>
  4. #include "windows.h"
  5. #include "wvglob.h"
  6. #include "winvn.h"
  7.  
  8. extern int WinVnDoComm (char *);
  9.  
  10.  
  11. /*-- function WinVnCommDlg ---------------------------------------------
  12.  *
  13.  *   Dialog function to process the Configure Communications
  14.  *   dialog box.
  15.  */
  16.  
  17. BOOL FAR PASCAL 
  18. WinVnCommDlg (hDlg, iMessage, wParam, lParam)
  19.      HWND hDlg;
  20.      unsigned iMessage;
  21.      WORD wParam;
  22.      LONG lParam;
  23. {
  24. #define MAXSTR  32
  25.   static int MyCommPortID;
  26.   static int MyCommParityID;
  27.   static int MyCommModeID;
  28. /* static BOOL MyAskComm;   */
  29.   static char pszMyCommSpeed[MAXCOMMSPEEDCHARS];
  30.   static char pszMyNNTPPort[MAXSTR];
  31.  
  32.   int write_ini = FALSE;
  33.   char *cptr;
  34.  
  35. #if 0
  36.   MessageBox (hWndConf, "At Beginning of WinVncncm",
  37.           "(debug)", MB_OK | MB_ICONASTERISK);
  38. #endif
  39.  
  40.   switch (iMessage)
  41.     {
  42.  
  43.     case WM_INITDIALOG:
  44.       if (AskComm == ASK_COMM_INITIAL)
  45.     AskComm = ASK_COMM_NEVER;
  46.       MyCommPortID = CommPortID;
  47.       MyCommParityID = CommParityID;
  48.       strcpy (pszMyCommSpeed, pszCommSpeed);
  49.       MyCommModeID = (UsingSocket ? ID_COMMTCP : ID_COMMSERIAL);
  50.  
  51.       CheckRadioButton (hDlg, IDD_COM1, IDD_COM2, CommPortID);
  52.       CheckRadioButton (hDlg, IDD_7EVEN, IDD_8NONE, CommParityID);
  53.       CheckRadioButton (hDlg, ID_COMMTCP, ID_COMMSERIAL, MyCommModeID);
  54.       CheckDlgButton (hDlg, ID_CONFIG_ASK_COMM, AskComm);
  55.       SetDlgItemText (hDlg, IDD_SPEED, pszMyCommSpeed);
  56.       SetDlgItemText (hDlg, ID_CONFIG_NNTP_SERVER, NNTPHost);
  57.       sprintf (pszMyNNTPPort, "%d", NNTPPort);
  58.       SetDlgItemText (hDlg, ID_CONFIG_NNTP_PORT, pszMyNNTPPort);
  59.       return TRUE;
  60.       break;
  61.  
  62.     case WM_COMMAND:
  63.       switch (wParam)
  64.     {
  65.     case ID_OK_SAVE:
  66.       write_ini = TRUE;
  67.     case IDOK:
  68.       GetDlgItemText (hDlg, IDD_SPEED, pszCommSpeed, MAXCOMMSPEEDCHARS - 1);
  69.       CommPortID = MyCommPortID;
  70.       CommParityID = MyCommParityID;
  71.       CommIDtoStr (CommPortID, CommParityID, pszCommSpeed, szCommString);
  72.       WinVnDoComm (szCommString);
  73.  
  74.       if (Initializing)
  75.         UsingSocket = (MyCommModeID == ID_COMMTCP);
  76.       GetDlgItemText (hDlg, ID_CONFIG_NNTP_SERVER, NNTPHost, MAXNNTPSIZE);
  77.       GetDlgItemText (hDlg, ID_CONFIG_NNTP_PORT, pszMyNNTPPort, MAXSTR);
  78.       NNTPPort = atoi (pszMyNNTPPort);
  79.       AskComm = IsDlgButtonChecked (hDlg, ID_CONFIG_ASK_COMM);
  80.  
  81.  
  82.       if (write_ini)
  83.         {
  84.           WritePrivateProfileString (szAppName, "CommString", szCommString, szAppProFile);
  85.           WritePrivateProfileString (szAppName, "NNTPHost", NNTPHost, szAppProFile);
  86.           WritePrivateProfileString (szAppName, "NNTPPort", pszMyNNTPPort, szAppProFile);
  87.           cptr = MyCommModeID == ID_COMMTCP ? "1" : "0";
  88.           WritePrivateProfileString (szAppName, "UseSocket", cptr, szAppProFile);
  89.           WritePrivateProfileInt (szAppName, "AskComm", AskComm, szAppProFile);
  90.         }
  91.       EndDialog (hDlg, TRUE);
  92.       break;
  93.  
  94.     case IDCANCEL:
  95.       EndDialog (hDlg, FALSE);
  96.       break;
  97.  
  98.     case ID_COMMTCP:
  99.     case ID_COMMSERIAL:
  100.       MyCommModeID = wParam;
  101.       CheckRadioButton (hDlg, ID_COMMTCP, ID_COMMSERIAL, MyCommModeID);
  102.       break;
  103.  
  104.  
  105.  
  106.     case IDD_COM1:
  107.     case IDD_COM2:
  108.       MyCommPortID = wParam;
  109.       CheckRadioButton (hDlg, IDD_COM1, IDD_COM2, wParam);
  110.       break;
  111.  
  112.     case IDD_7EVEN:
  113.     case IDD_8NONE:
  114.       MyCommParityID = wParam;
  115.       CheckRadioButton (hDlg, IDD_7EVEN, IDD_8NONE, wParam);
  116.       break;
  117.  
  118.     default:
  119.       return FALSE;
  120.     }
  121.       break;
  122.  
  123. #if 0
  124.       case WM_PAINT;
  125.       InvalidateRect (
  126.                break;
  127. #endif
  128.     default:
  129.       return FALSE;
  130.       break;
  131.     }
  132.   return TRUE;
  133. }
  134.  
  135. /*--- Function CommIDtoStr --------------------------------------
  136.  *
  137.  *   Takes information relating to comm port configuration and creates
  138.  *   a string of the form to give to the MODE command.
  139.  *
  140.  *   Entry    Port      is the port (an IDD_* variable)
  141.  *            Parity    is the parity/data bits infor (an IDD_* variable)
  142.  *            szSpeed     is the speed, in character form
  143.  *
  144.  *   Exit     CommStr    is the string; e.g., "COM1:2400,n,8"
  145.  *            Function value is non-zero if error.
  146.  */
  147. int
  148. CommIDtoStr (Port, Parity, szSpeed, CommStr)
  149.      int Port, Parity;
  150.      char *szSpeed;
  151.      char *CommStr;
  152. {
  153.   register char *ptr;
  154.   int myPort;
  155.  
  156.   ptr = CommStr;
  157.   strcpy (ptr, "COM");
  158.   ptr += 3;
  159.   *(ptr++) = (char) (Port == IDD_COM1 ? '1' : '2');
  160.   *(ptr++) = ':';
  161.  
  162.   for (; *szSpeed; *(ptr++) = *(szSpeed++));
  163.   *(ptr++) = ',';
  164.   if (Parity == IDD_7EVEN)
  165.     {
  166.       strcpy (ptr, "e,7");
  167.     }
  168.   else
  169.     {
  170.       strcpy (ptr, "n,8");
  171.     }
  172.  
  173.   return (0);
  174. }
  175.  
  176. /*-- function WinVnSaveArtDlg ---------------------------------------
  177.  *
  178.  *  Dialog function to handle Save Article dialog box.
  179.  */
  180.  
  181. BOOL FAR PASCAL 
  182. WinVnSaveArtDlg (hDlg, iMessage, wParam, lParam)
  183.      HWND hDlg;
  184.      unsigned iMessage;
  185.      WORD wParam;
  186.      LONG lParam;
  187. {
  188.   static int MyAppend;
  189.  
  190. #if 0
  191.   MessageBox (hWndConf, "At Beginning of WinVnSaveArtDlg",
  192.           "(debug)", MB_OK | MB_ICONASTERISK);
  193. #endif
  194.  
  195.   switch (iMessage)
  196.     {
  197.  
  198.     case WM_INITDIALOG:
  199.       MyAppend = SaveArtAppend;
  200.  
  201.       CheckDlgButton (hDlg, IDD_APPEND, MyAppend);
  202.       SetDlgItemText (hDlg, IDD_FILENAME, SaveArtFileName);
  203.       return TRUE;
  204.       break;
  205.  
  206.     case WM_COMMAND:
  207.       switch (wParam)
  208.     {
  209.     case IDOK:
  210.       GetDlgItemText (hDlg, IDD_FILENAME, SaveArtFileName, MAXFILENAME - 1);
  211.  
  212.       SaveArtAppend = MyAppend;
  213.       if (!MRRWriteDocument (ActiveArticleDoc, sizeof (TypText), SaveArtFileName, SaveArtvRef, SaveArtAppend))
  214.         {
  215.           MessageBox (hWndConf, "Could not write to file", "Problems saving file", MB_OK | MB_ICONEXCLAMATION);
  216.         }
  217.       EndDialog (hDlg, TRUE);
  218.       break;
  219.  
  220.     case IDCANCEL:
  221.       EndDialog (hDlg, FALSE);
  222.       break;
  223.  
  224.     case IDD_APPEND:
  225.       MyAppend = !MyAppend;
  226.       CheckDlgButton (hDlg, IDD_APPEND, MyAppend);
  227.       break;
  228.  
  229.     default:
  230.       return FALSE;
  231.     }
  232.       break;
  233.  
  234.     default:
  235.       return FALSE;
  236.       break;
  237.     }
  238.   return TRUE;
  239. }
  240.  
  241. /*-- function WinVnFindDlg ---------------------------------------
  242.  *
  243.  *  Dialog function to handle Search dialog box.
  244.  */
  245.  
  246. BOOL FAR PASCAL 
  247. WinVnFindDlg (hDlg, iMessage, wParam, lParam)
  248.      HWND hDlg;
  249.      unsigned iMessage;
  250.      WORD wParam;
  251.      LONG lParam;
  252. {
  253.   static int MyAppend;
  254.  
  255. #if 0
  256.   MessageBox (hWndConf, "At Beginning of WinVnSaveArtDlg",
  257.           "(debug)", MB_OK | MB_ICONASTERISK);
  258. #endif
  259.  
  260.   switch (iMessage)
  261.     {
  262.  
  263.     case WM_INITDIALOG:
  264.       SetDlgItemText (hDlg, IDD_SEARCH_STRING, FindDoc->SearchStr);
  265.       return TRUE;
  266.       break;
  267.  
  268.     case WM_COMMAND:
  269.       switch (wParam)
  270.     {
  271.     case IDOK:
  272.       GetDlgItemText (hDlg, IDD_SEARCH_STRING, FindDoc->SearchStr, MAXFINDSTRING - 1);
  273.  
  274.       EndDialog (hDlg, TRUE);
  275.       break;
  276.  
  277.     case IDCANCEL:
  278.       EndDialog (hDlg, FALSE);
  279.       break;
  280.  
  281.     default:
  282.       return FALSE;
  283.     }
  284.       break;
  285.  
  286.     default:
  287.       return FALSE;
  288.       break;
  289.     }
  290.   return TRUE;
  291. }
  292.  
  293. /*-- function WinVnSubjectDlg ---------------------------------------
  294.  *
  295.  *  Dialog function to query the user for a posting's subject
  296.  */
  297.  
  298. BOOL FAR PASCAL 
  299. WinVnSubjectDlg (hDlg, iMessage, wParam, lParam)
  300.      HWND hDlg;
  301.      unsigned iMessage;
  302.      WORD wParam;
  303.      LONG lParam;
  304. {
  305.   static int MyAppend;
  306.  
  307.   switch (iMessage)
  308.     {
  309.  
  310.     case WM_INITDIALOG:
  311.       SetDlgItemText (hDlg, IDD_SUBJECT_STRING, SubjectString);
  312.       return TRUE;
  313.       break;
  314.  
  315.     case WM_COMMAND:
  316.       switch (wParam)
  317.     {
  318.     case IDOK:
  319.       GetDlgItemText (hDlg, IDD_SUBJECT_STRING, SubjectString, MAXSUBJECTSTRING - 1);
  320.  
  321.       EndDialog (hDlg, TRUE);
  322.       break;
  323.  
  324.     case IDCANCEL:
  325.       EndDialog (hDlg, FALSE);
  326.       break;
  327.  
  328.     default:
  329.       return FALSE;
  330.     }
  331.       break;
  332.  
  333.     default:
  334.       return FALSE;
  335.       break;
  336.     }
  337.   return TRUE;
  338. }
  339.  
  340. /*-- function WinVnDoListDlg ---------------------------------------
  341.  *
  342.  *  Dialog function to ask whether we should check for new
  343.  *  newsgroups.
  344.  */
  345.  
  346. BOOL FAR PASCAL 
  347. WinVnDoListDlg (hDlg, iMessage, wParam, lParam)
  348.      HWND hDlg;
  349.      unsigned iMessage;
  350.      WORD wParam;
  351.      LONG lParam;
  352. {
  353.  
  354.   switch (iMessage)
  355.     {
  356.  
  357.     case WM_COMMAND:
  358.       switch (wParam)
  359.     {
  360.     case IDOK:
  361.  
  362.       EndDialog (hDlg, TRUE);
  363.       break;
  364.  
  365.     case IDCANCEL:
  366.  
  367.       EndDialog (hDlg, FALSE);
  368.       break;
  369.  
  370.     default:
  371.       return FALSE;
  372.     }
  373.       break;
  374.  
  375.     default:
  376.       return FALSE;
  377.       break;
  378.     }
  379.   return TRUE;
  380. }
  381.  
  382.  
  383. /*--- Function WinVnPersonalInfoDlg ----------------------------------
  384.  *
  385.  *  Dialog function to obtain personal configuration info
  386.  *  (Name, email address, etc.) from the user.
  387.  */
  388.  
  389. BOOL FAR PASCAL 
  390. WinVnPersonalInfoDlg (hDlg, iMessage, wParam, lParam)
  391.      HWND hDlg;
  392.      unsigned iMessage;
  393.      WORD wParam;
  394.      LONG lParam;
  395. {
  396. #define MAXSTR  32
  397. #if 0
  398.   static char *pszMyUserName;
  399.   static char *pszMyMailAddress;
  400.   static char *pszMyOrganization;
  401. #endif
  402.  
  403.   int write_ini = FALSE;
  404.   int dialog_val;
  405.   char *cptr;
  406.  
  407.  
  408.   switch (iMessage)
  409.     {
  410.  
  411.     case WM_INITDIALOG:
  412. #if 0
  413.       pszMyUserName = malloc (MAILLEN);
  414.       pszMyMailAddress = malloc (MAILLEN);
  415.       pszMyOrganization = malloc (MAILLEN);
  416.  
  417.       strcpy (pszMyOrganization, Organization);
  418.       strcpy (pszMyUserName, UserName);
  419.       strcpy (pszMyMailAddress, MailAddress);
  420. #endif
  421.  
  422.       SetDlgItemText (hDlg, ID_CONFIG_EMAIL, MailAddress);
  423.       SetDlgItemText (hDlg, ID_CONFIG_NAME, UserName);
  424.       SetDlgItemText (hDlg, ID_CONFIG_ORG, Organization);
  425.       return TRUE;
  426.       break;
  427.  
  428.     case WM_COMMAND:
  429.       switch (wParam)
  430.     {
  431.     case ID_OK_SAVE:
  432.       write_ini = TRUE;
  433.     case IDOK:
  434.       GetDlgItemText (hDlg, ID_CONFIG_NAME, UserName, MAILLEN - 1);
  435.       GetDlgItemText (hDlg, ID_CONFIG_EMAIL, MailAddress, MAILLEN - 1);
  436.       GetDlgItemText (hDlg, ID_CONFIG_ORG, Organization, MAILLEN - 1);
  437.  
  438.       if (write_ini)
  439.         {
  440.           WritePrivateProfileString (szAppName, "UserName", UserName, szAppProFile);
  441.           WritePrivateProfileString (szAppName, "MailAddress", MailAddress, szAppProFile);
  442.           WritePrivateProfileString (szAppName, "Organization", Organization, szAppProFile);
  443.         }
  444.       dialog_val = TRUE;
  445.       goto endit;
  446.       break;
  447.  
  448.     case IDCANCEL:
  449.       dialog_val = FALSE;
  450.     endit:;
  451. #if 0
  452.       free (pszMyUserName);
  453.       free (pszMyMailAddress);
  454.       free (pszMyOrganization);
  455. #endif
  456.       EndDialog (hDlg, dialog_val);
  457.       break;
  458.  
  459.     default:
  460.       return FALSE;
  461.     }
  462.       break;
  463.  
  464.     default:
  465.       return FALSE;
  466.       break;
  467.     }
  468.   return TRUE;
  469. }
  470.  
  471.  
  472.  
  473. /*--- Function WinVnMiscDlg ---------------------------------------------
  474.  *
  475.  *  Dialog function to obtain miscellaneous configuration info
  476.  *  (whether we should open a new window for each group, etc.)
  477.  *  from the user.
  478.  */
  479.  
  480. BOOL FAR PASCAL 
  481. WinVnMiscDlg (hDlg, iMessage, wParam, lParam)
  482.      HWND hDlg;
  483.      unsigned iMessage;
  484.      WORD wParam;
  485.      LONG lParam;
  486. {
  487.   int write_ini = FALSE;
  488.   int dialog_val;
  489.   int item;
  490.  
  491.  
  492.   switch (iMessage)
  493.     {
  494.  
  495.     case WM_INITDIALOG:
  496.       CheckRadioButton (hDlg, ID_DOLIST_BASE, ID_DOLIST_ASK, DoList + ID_DOLIST_BASE);
  497.       CheckDlgButton (hDlg, ID_CONFIG_APPEND, SaveArtAppend);
  498.       CheckDlgButton (hDlg, ID_CONFIG_NEW_WND_GROUP, ViewNew);
  499.       CheckDlgButton (hDlg, ID_CONFIG_NEW_WND_ARTICLE, NewArticleWindow);
  500.       CheckDlgButton (hDlg, ID_CONFIG_ARTICLE_FIXED_FONT, ArticleFixedFont);
  501.  
  502.       return TRUE;
  503.       break;
  504.  
  505.     case WM_COMMAND:
  506.       switch (wParam)
  507.     {
  508.     case ID_OK_SAVE:
  509.       write_ini = TRUE;
  510.     case IDOK:
  511.       SaveArtAppend = (IsDlgButtonChecked (hDlg, ID_CONFIG_APPEND) != 0);
  512.       ViewNew = (IsDlgButtonChecked (hDlg, ID_CONFIG_NEW_WND_GROUP) != 0);
  513.       NewArticleWindow = (IsDlgButtonChecked (hDlg, ID_CONFIG_NEW_WND_ARTICLE) != 0);
  514.       ArticleFixedFont = (IsDlgButtonChecked (hDlg, ID_CONFIG_ARTICLE_FIXED_FONT) != 0);
  515.  
  516.       for (item = ID_DOLIST_BASE; item <= ID_DOLIST_ASK; item++)
  517.         {
  518.           if (IsDlgButtonChecked (hDlg, item))
  519.         {
  520.           DoList = item - ID_DOLIST_BASE;
  521.         }
  522.         }
  523.  
  524.       if (write_ini)
  525.         {
  526.           WritePrivateProfileInt (szAppName, "SaveArtAppend", SaveArtAppend, szAppProFile);
  527.           WritePrivateProfileInt (szAppName, "NewWndGroup", ViewNew, szAppProFile);
  528.           WritePrivateProfileInt (szAppName, "NewWndArticle", NewArticleWindow, szAppProFile);
  529.           WritePrivateProfileInt (szAppName, "DoList", DoList, szAppProFile);
  530.           WritePrivateProfileInt (szAppName, "ArticleFixedFont", ArticleFixedFont, szAppProFile);
  531.         }
  532.       dialog_val = TRUE;
  533.       goto endit;
  534.       break;
  535.  
  536.     case IDCANCEL:
  537.       dialog_val = FALSE;
  538.     endit:;
  539.       EndDialog (hDlg, dialog_val);
  540.       break;
  541.  
  542.     default:
  543.       return FALSE;
  544.     }
  545.       break;
  546.  
  547.     default:
  548.       return FALSE;
  549.       break;
  550.     }
  551.   return TRUE;
  552.  
  553. }
  554.  
  555. /*--- Function WinVnAppearanceDlg ----------------------------------
  556.  *
  557.  *  Dialog function to obtain window appearance configuration info
  558.  *  (font, color, etc.)
  559.  *  from the user.
  560.  */
  561.  
  562. BOOL FAR PASCAL 
  563. WinVnAppearanceDlg (hDlg, iMessage, wParam, lParam)
  564.      HWND hDlg;
  565.      unsigned iMessage;
  566.      WORD wParam;
  567.      LONG lParam;
  568. {
  569.  
  570. }
  571.  
  572. BOOL
  573. WritePrivateProfileInt (lpAppName, lpKeyName, intval,lpProFile)
  574.      char far *lpAppName;
  575.      char far *lpKeyName;
  576.      char far *lpProFile;
  577.      int intval;
  578. {
  579.   char msg[20];
  580.  
  581.   itoa (intval, msg, 10);
  582.   return (WritePrivateProfileString (lpAppName, lpKeyName, msg, lpProFile));
  583. }
  584.